<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        项目信息-跟踪阶段
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui2.0/css/layui.css" media="all">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../../../../js/xm-select.js"></script>

</head>
<!--借还流水-->
<style>
    .layui-form-label {
        width: 150px !important;
    }
    .text_btn{margin-bottom: 30px;}
</style>

<body>
<div class="x-body" id="app">
    <div class="layui-tab-item layui-show layui-form">
                    <div class="heading" id="checkbox">

                    </div>
                    <div class="panel-body">
                        <div class="col-xs-5 fl">
                            <ul class="layui-timeline">
                                <li class="layui-timeline-item" v-for="u in statistics" :key="u.id">
                                    <i class="layui-icon layui-timeline-axis"></i>
                                    <div class="layui-timeline-content layui-text">

                                        <h4 class="layui-timeline-title red_color">{{u.belongStage}}</h4>
                                        <p>
                                            时间：{{u.createTime}}
                                            <br>人员：{{u.operatorName}}
                                            <br>内容：{{u.operationContent}}
                                            <!--       <img :src="bindSrcBillAttachment(u.picUrl)"   alt="">-->
                                        </p>
                                    </div>
                                </li>

                            </ul>
                        </div>
                        <div class="col-xs-7" id="enclosureList">

<!--                            <div class="text_btn">-->
<!--                                施工现场-->
<!--                                <button type="button" class="layui-btn" id="sgxc" style="float: right;">-->
<!--                                    <i class="layui-icon">&#xe67c;</i>上传附件-->
<!--                                </button>-->
<!--                            </div>-->





<!--                            <div class="text_btn">-->
<!--                                小区概况-->
<!--                                <button type="button" class="layui-btn" id="xqgk" style="float: right;">-->
<!--                                    <i class="layui-icon">&#xe67c;</i>上传附件-->
<!--                                </button>-->
<!--                            </div>-->

<!--                            <table class="layui-table" id="test2" lay-filter="test">-->
<!--                            </table>-->

<!--                            <script type="text/html" id="barDemo">-->
<!--                                <a class="layui-btn layui-btn-xs" lay-event="view">查看</a>-->
<!--                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
<!--                            </script>-->
                        </div>
                    </div>

                </div>
</div>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" style="background: #673ab7" lay-event="download">下载</a>
    <a class="layui-btn layui-btn-xs" lay-event="view">编辑</a>
    <a  lay-event="giveUp_pro" class="ml-5 layui-btn-xs layui-btn layui-btn-warm" >查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui-v2.5.7/layui/layui.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        element = layui.element;//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");
    var tabId = getQueryVariable("tabId");
    var stageName=getQueryVariable("stageName");
    // console.log(recordId);
    console.log(tabId);
    // console.log( decodeURI(stageName) );

    layui.use(['laydate', 'form', 'layer','upload','element', 'table'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var upload = layui.upload;
            var element=layui.element;
            var table = layui.table;

            var steplist={};
            let request = {
                url: "xa/projectTemplate/findProjectStageInfoByType",
                data: {
                    userId:$userId,
                    parentId: tabId,
                    fileType:0,
                },

            };
            sendRequest(request, (data) => {

                steplist=data.data;

                var checkboxHtml = "";
                steplist.forEach((res, index) => {
                    if(res.ifSelect==1){
                        checkboxHtml += '<input  autocomplete="off"  type="checkbox" name="'+res.name+'" title="'+res.name+'" value="'+res.id+'"  lay-skin="primary"  lay-filter="switchTest" checked> ';
                    }else {
                        checkboxHtml += '<input  autocomplete="off"  type="checkbox" name="'+res.name+'" title="'+res.name+'" value="'+res.id+'"  lay-skin="primary"  lay-filter="switchTest"> ';
                    }
                });
                $('#checkbox').html(checkboxHtml);
                form.render();
            });

            form.on('checkbox(switchTest)', function (data) {
                // console.log( data );　　
                if(data.elem.checked === true){　　　　　　//判断当前多选框是选中还是取消选中
                    let request = {
                        url: "xa/projectTemplate/updateProjectTemplateSelect",
                        data: {
                            userId:$userId,
                            id: data.value,
                            ifSelect:1,
                        },
                        method: "post",

                    };
                    sendRequest(request, (data) => {
                        // console.log(data);
                    });
                }else {

                    let request = {
                        url: "xa/projectTemplate/updateProjectTemplateSelect",
                        data: {
                            userId:$userId,
                            id: data.value,
                            ifSelect:0,
                        },
                        method: "post",

                    };
                    sendRequest(request, (data) => {
                        // console.log(data);
                    });
                }

            });

            let request1 = {
                url: "xa/projectTemplate/findProjectStageInfoByType",
                headers: {
                    "token": $token,
                },

                data: {
                    userId:$userId,
                    parentId: tabId,
                    fileType:1,
                },

            };
            sendRequest(request1, (data) => {

                enclosureList=data.data;
                var enclosureListHtml = "";
                enclosureList.forEach((res, index) => {
                    var res=res;

                    $('#enclosureList').append('<div class="text_btn">'+res.name+' <button type="button" class="layui-btn" id="file'+res.id +'" style="float: right;"> <i class="layui-icon">&#xe67c;</i>上传附件 </button> </div> '+'<table class="layui-table" id="table'+res.id+'" lay-filter="table'+res.id+'"> </table>');

                    var table1 = table.render({
                        elem: '#table'+res.id,
                        url: $baseUrl + 'xa/projectTemplateFile/getProjectTemplateFileList',
                        where: {
                            userId:$userId,
                            projectId: recordId,
                            projectTemplateStageId: res.id
                        },
                        headers: {
                            token: $token
                        }
                        , toolbar: '#toolbarDemo',

                        // toolbar: true,
                        cols: [
                            [
                                {
                                    // field: 'id',
                                    type:'numbers',
                                    title: '序号',
                                },
                                {
                                    field: 'fileName',
                                    title: '附件',
                                    style: 'color: #145CCD;'
                                },
                                {
                                    field: 'status',
                                    title: '操作',
                                    width: 270,
                                    templet: '#barDemo',

                                }]
                        ],
                        request: {
                            pageName: 'pageNum', //页码的参数名称，默认：page
                            limitName: 'pageSize',
                        },
                        response: {
                            statusName: 'code' //规定数据状态的字段名称，默认：code
                            ,
                            statusCode: 0 //规定成功的状态码，默认：0
                            ,
                            msgName: 'msg' //规定状态信息的字段名称，默认：msg
                            ,
                            countName: 'total' //规定数据总数的字段名称，默认：count
                            ,
                            dataName: 'data', //规定数据列表的字段名称，默认：data
                        },
                        id: 'table'+res.id,
                        height: 'auto',
                        even: true,
                        done: function (res, curr, count) {
                            // console.log(res);
                        }
                    });
                    table.on('tool(table'+res.id+')', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                        let data = obj.data; //获得当前行数据
                        // console.log(data);
                        let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                        if (layEvent === 'del') { //删除
                            layer.confirm('是否确认删除 【' + data.id + '】 ？', {
                                icon: 3,
                                title: '提示'
                            }, function (index) {
                                let request = {
                                    url:"xa/projectTemplateFile/delProjectTemplateFile/"+data.id,
                                    data: {
                                        userId: $userId,
                                    },
                                    method: "delete",
                                };
                                sendRequest(request, (data) => {
                                    if (data.code === 0) {
                                        layer.msg("删除成功", {
                                            icon: 1
                                        });
                                        table1.reload();
                                    } else {
                                        layer.msg("删除失败，请稍后再试！", {
                                            icon: 5
                                        });
                                    }
                                });
                                layer.close(index);
                            });
                        }
                            else if (layEvent === 'view') { //编辑
                                x_admin_show('修改附件名', 'tracking_add.html?Id=' + data.id +'&fileName='+data.fileName,"600","300")
                        }
                      else if (layEvent === 'giveUp_pro') { //放弃项目
                            layer.open({
                                type: 1,
                                title: '区域图片',
                                skin: 'layui-layer-rim', //加上边框
                                area: ['80%', '80%'], //宽高 t.width() t.height()
                                shadeClose: true, //开启遮罩关闭
                                end: function (index, layero) {
                                    return false;
                                },
                                content: '<div style="text-align:center"><img src="'+baseHead+"/other/viewUploadFile?id=" + data.fileUrl + '" /></div>'
                            });
                        }

                        else if (layEvent === 'download') { //下载

                            var last ='.'+ data.fileUrl.split('.')[1];

                            window.location.href=$baseUrl+'/other/downLoadFile?id='+ data.fileUrl +'&userId='+ $userId + '&fileName=' + data.fileName + last;
                        }
                    });





                    var uploadInst = upload.render({
                        elem: '#file'+res.id //绑定元素
                        ,url: $baseUrl +'other/fileUpload1' //上传接口

                        ,done: function(data){
                            //上传完毕回调
                            // console.log(data);
                            var file=data.data;
                            var reg = /([^\\/]+)\.([^\\/]+)/i;
                            reg.test(file);
                            var fileName=RegExp.$1;
                            // console.log(fileName);
                            // console.log(res.id);
                            let request = {
                                url: "xa/projectTemplateFile/addAndUpProjectTemplateFile",
                                data: {
                                    userId:$userId,
                                    projectId:recordId,
                                    projectTemplateStageId:res.id,
                                    fileUrl:data.data,
                                    fileName:fileName,
                                },
                                method:"post",

                            };
                            sendRequest(request, (data) => {
                                // console.log(data);
                                if (data.code === 0) {
                                    layer.msg("上传成功", {
                                        icon: 1
                                    });
                                    table1.reload();
                                } else {
                                    layer.msg("上传失败，请稍后再试！", {
                                        icon: 5
                                    });
                                }
                            });

                        }
                        ,error: function(){
                            //请求异常回调
                        }
                    });


                });

                form.render();
            });



        });

    function p_admin_add(title,url,w,h){
        p_admin_show(title,url,w,h);
    }


</script>

<script>

    var vm = new Vue({
        el: "#app",
        data: {
            statistics:{},

        },
        mounted() {
            this.statisticsFun();
        },
        methods: {

            bindSrcBillAttachment(value) {
                return $baseUrl +
                    'other/viewUploadFile2?id=' + value;
            },

            statisticsFun() {
                let request = {
                    url: "xa/projectLog/getNowStageLogs",
                    data: {
                        userId: $userId,
                        projectId:recordId,
                        logType:1,
                        stageName:decodeURI(stageName),

                    },
                };
                sendRequest(request, (data) => {
                    // console.log(data);
                    this.statistics=data.data;

                });


            }
        }

    });

</script>

</body>

</html>
